//
//  LWHelper.swift
//  LWColumnShapeView
//
//  Created by 赖灵伟 on 15/10/28.
//  Copyright © 2015年 深圳创世易明科技有限公司. All rights reserved.
//

import UIKit


class LWHelper: NSObject {

    /**根据类型和等级获取称号*/
    class func fetchTitle(type: String, level: Int) -> String {
        
        var index: Int = 0
        switch level {
        case 1: index = 0
        case 2: index = 1
        case 3: index = 2
        case 4: index = 3
        case 5, 6: index = 4
        case 7, 8, 9: index = 5
        default: index = 6
        }
        
        var title: String = "粗通皮毛"
        if let filePath = NSBundle.mainBundle().pathForResource("TypeTitle", ofType: "plist") {
            let typeTitleDic =  NSDictionary(contentsOfFile: filePath)
            
            if let titleAry = typeTitleDic?.objectForKey(type) as? [String] {
                title = titleAry[index] ?? "粗通皮毛"
            }
        }
        
        return title
    }
    
/**玫瑰图根据等级获取称号*/
    class func roseFetchTitle(level: Int) ->String {
        
        var index = String()
        switch level {
        case 1: index = "LV 1"
        case 2: index = "LV 2"
        case 3: index = "LV 3"
        case 4: index = "LV 4"
        case 5, 6: index = "LV 6"
        case 7, 8, 9: index = "LV 8"
        default: index = "LV 11"
        }
        var title = String()
        if let filePath = NSBundle.mainBundle().pathForResource("TypeScore", ofType:"plist"){
        let typeScoreDic = NSDictionary(contentsOfFile: filePath)
            title = (typeScoreDic?.valueForKeyPath(index))! as! String
        }
        return title
    }
     
     
    
    /**根据分数获取等级*/
    class func fetchLevel(score: CGFloat) -> Int {
        if score <= 20 {
            return 1
        } else if score >= 21 && score <= 40 {
            return 2
        } else if score >= 41 && score <= 60 {
            return 3
        } else if score >= 61 && score <= 80 {
            return 4
        } else if score >= 81 && score <= 90 {
            return 6
        } else if score >= 91 && score <= 99 {
            return 8
        } else {
            return 11
        }
    }
    
}
